﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace YawetagLib.Data
{
    public abstract class QueryableRepository<TEntity> : CrudRepository<TEntity>, IQueryable<TEntity> where TEntity : class
    {
        protected QueryableRepository(IDataContext dataContext)
            : base(dataContext)
        {
        }

        public IEnumerator<TEntity> GetEnumerator()
        {
            return Queryable.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return Queryable.GetEnumerator();
        }

        public Expression Expression
        {
            get { return Queryable.Expression; }
        }

        public Type ElementType
        {
            get { return Queryable.ElementType; }
        }

        public IQueryProvider Provider
        {
            get { return Queryable.Provider; }
        }

        protected abstract IQueryable<TEntity> Queryable { get; }

        protected new IQueryableDataContext DataContext
        {
            get { return (IQueryableDataContext)base.DataContext; }
        }
    }
}
